function axios({
    url,
    params = {},
    data = {},
    method = 'GET'
}) {
    return new Promise((resolve, reject) => {
        const xhr = new XMLHttpRequest()
        method = method.toLocaleUpperCase()
        // 拼接字符串
        if (Object.keys(params).length) {
            const str = Object.keys(params).map(item => item + '=' + params[item]).join('&')
            url += '?' + str
        }
        // 设置参数
        xhr.open(method, url, true)
        // 监听状态
        xhr.onreadystatechange = () => {
            if (xhr.readyState === 4) {
                if (xhr.status >= 200 && xhr.status < 300) {
                    const responseData = {
                        data: JSON.parse(xhr.responseText),
                        status: xhr.status,
                        statusText: xhr.statusText
                    }
                    resolve(responseData)
                } else {
                    reject(new Error(`请求出错了~ 状态码${xhr.status}`))
                }
            }
        }
        // 发送请求
        if (method !== 'GET') {
            xhr.setRequestHeader('Content-Type', 'application/json;charset=utf8')
            xhr.send(JSON.stringify(data))
        } else {
            xhr.send()
        }
    })
}

// 静态方法
axios.get = (url, config) => {
    return axios({
        ...config,
        url,
        method: 'GET'
    })
}

axios.delete = (url, config) => {
    return axios({
        ...config,
        url,
        method: 'DELETE'
    })
}

axios.post = (url, data, config) => {
    return axios({
        ...config,
        url,
        data,
        method: 'post'
    })
}

axios.put = (url, data, config) => {
    return axios({
        ...config,
        url,
        data,
        method: 'put'
    })
}